import { requestWrapper } from '../requestPackage/requestWrapper'
import { isDev, PROJECTNAME } from '../globalData'

const postWechatPhoneNumber = (params, data) => {
    requestWrapper({
        ...params,
        url: `/restaurant-user/user/getWeiUserPhoneNumberToDoBing`
    }, data)
};

const getFindBylevId = (params, data) => {
    requestWrapper({
        ...params,
        url: `/restaurant-store/shop/findBylevId/${params.levId}`
    }, data)
};

/**
 * @author Dom
 * @description: 旧版本商户注册接口
*/
const postAddShop = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-store/shop/addShop'
    }, data)
};

const postAddShopRegister = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-store/shop/addShopRegister'
    }, data)
};

const postEditShop = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-store/shop/editShop'
    }, data)
};

const postShopList = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-store/shop/getShopList'
    }, data)
};

const postShopData = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-store/shop/getShopData'
    }, data)
};

const postIndexList = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-store/shop/getIndexList'
    }, data)
};

const postStores = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-user/index/getStores'
    }, data)
};

const postCancelSeason = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-order/orderManagement/getCancelSeason'
    }, data)
};

const postPartCancel = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-order/order/partCancel'
    }, data)
};

const postMine = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-user/index/mine'
    }, data)
};

const postSpuList = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-order/dishes/spuList'
    }, data)
};

const postSkuInfo = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-order/dishes/skuInfo'
    }, data)
};

/**
 * @author Dom
 * @param params, type: object
 * state: 请求配置, 具体说明参照 /utils/requestWrapper.js
 * @param data, type: object
 * state: { spuShopId: 店铺Id, spuName: 用于搜索的value, pageNum: 当前页码, 即需要哪页就传哪页 }
 * @description: 店内菜品根据菜品名模糊查询
 */
const postDishSpuName = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-order/dishes/dishSpuName'
    }, data)
};

const postPlaceOrder = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-order/order/placeOrder'
    }, data)
};

/**
 * @author Dom
 * @description: 支付查询
*/
const postPayQuery = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-order/order/payQuery'
    }, data)
};

const postUser = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-order/orderManagement/user'
    }, data)
};

const postUnbind = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-user/user/unbind'
    }, data)
};

const postOrderDetails = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-order/order/orderDetails'
    }, data)
};

// 获取优惠券
const postCoupon = (params, data) => {
    requestWrapper({
        ...params,
        url: isDev ? 'https://smarthome.17wo.cn/test/activity/couponUsed/getCoupon' : 'https://smarthome.17wo.cn/activity/couponUsed/getCoupon'
    }, data)
};

// 获取手机号
const postEntryPhone = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-store/shop/entryPhone'
    }, data)
};

// 商家菜品管理模块
// 新增类目
const postAddCategory = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-order/dishes/addCategory'
    }, data)
};

// 删除类目
const postDelCategory = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-order/dishes/delCategory'
    }, data)
};

// 新增菜品
const postInsertSaveDish = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-order/dishes/insertSaveDish'
    }, data)
};

// 编辑菜品
const postUpdateSaveDish = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-order/dishes/updateSaveDish'
    }, data)
};

// 获取类目列表
const postCategoryList = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-order/dishes/categoryList'
    }, data)
};

// 获取编辑信息
const postDishMsg = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-order/dishes/getDishMsg'
    }, data)
};

// 获取打印机列表
const postPrinterlist = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-order/printer/printerlist'
    }, data)
};

// 后厨打印机列表
const postBackPrinterlist = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-order/printer/backprinterlist'
    }, data)
};

// 获取打印机信息
const postPrinterinfo = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-order/printer/printerinfo'
    }, data)
};

// 更新打印机信息
const postUpdateprinter = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-order/printer/updateprinter'
    }, data)
};

// 获取打印机绑定的菜品数量
const postCount = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-order/printer/getcount'
    }, data)
};

// 删除打印机
const postRemoveprinter = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-order/printer/removeprinter'
    }, data)
};

// 添加打印机
const postAddprinter = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-order/printer/addprinter'
    }, data)
};

// 根据用户Id查询用户所有审核通过的门店
const postFindStoreByUserId = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-store/shop/findStoreBySmartUserId'
    }, data)
};

// 检查门店用户是否有权限进行二维码绑定
const postCheckQrBindJurisdiction = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-store/shop/checkQrBindJurisdiction'
    }, data)
};

const postBindStoreQR = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-store/shop/V1.0/bindStoreQR'
    }, data)
};

// 编辑二维码信息
const postUpdateStoreQrCode = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-store/shop/updateStoreQrCode'
    }, data)
};

// spu上下架（spu）
const postUpdateOnsale = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-order/dishes/updateOnsale'
    }, data)
};

const postDishDelete = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-order/dishes/dishDelete'
    }, data)
};
// 商家菜品管理模块 end

/**
 * @author Dom
 * @param data, type: object
 * state: { storeId }, storeId, 门店ID
 * @description: post类型请求, 查询门店信息, 包含门店信息, 资质信息, 渠道信息
 * eg: storeId=1560111149137LOPCBS81
*/
const getStoreManagerInfo = (params, data) => {
    wx.request({
        url: `${PROJECTNAME}/restaurant-store/shop/getStoreManagerInfo`,
        data,
        success (res) {
            params.success(res.data);
        }
    })
};

// 编辑门店信息
const postUpdateStore = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-store/shop/updateStore'
    }, data)
};

// 改变门店状态
const postChangeStoreStatus = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-store/shop/changeStoreStatus'
    }, data)
};

/**
 * @author Dom
 * @param data, type: object
 * state: { storeId }, storeId, 门店ID
 * @description: 查询营业配置信息, 加密返回
 */
const postStoreConfigData = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-store/shop/getStoreConfigData'
    }, data)
};

/**
 * @author Dom
 * @param params, type: object
 * state: 请求配置, 具体说明参照 /utils/requestWrapper.js
 * @param data, type: object
 * state:
 * 以下参数除了storeId, 均为选填
 * {
 *          storeId: '门店ID',
 *          isAppoint: 1, //是否开启预约点餐, 0 = 否, 1 = 是)
 *          isTakeout: 1, //是否开启外卖配送, 0 = 否, 1 = 是)
 *          businessTime: '1,2', //营业时间, 1-7表示星期一到星期天
 *          appointTime: [ //预约时间段
 *                  {
 *                      start: '12:00', //开始时间
 *                      end: '18:00' //结束时间
 *                  }
 *          ],
 *          appointStandbytime: 18, //备货时间
 *          appointInterval: 18, //预约时间间隔
 *          appointLongest: 36, //最长预约时间
 *          isUnreserved: 1, //非预约就餐/外卖配送时间段下单
 *          storeNotice: '门店公告', //门店公告
 *          noticeLink: '公告链接', //公告链接
 *          boxFee: 1, //餐盒费用, 0 = 按人计价, 1 = 按单计价
 *          originalPrice: 0.1, //餐盒原价
 *          specialPrice: 0.02, //餐盒优化价
 * }
 * @description: 更新营业配置信息, 加密返回
 */
const postEditStoreConfigData = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-store/shop/editStoreConfigData'
    }, data)
};

const postUpdateAptitude = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-store/shop/updateAptitude'
    }, data)
};

// 编辑客户经理信息
const postUpdateManager = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-store/shop/updateManager'
    }, data)
};

/**
 * @author Dom
 * @param params, type: object
 * state: { success: function(){} }, 暂时只能传递一个success callback
 * @param data , type: object
 * state: { storeBindingPhone }, 餐厅入驻时办理的手机卡号码
 * @return: {
    "code": 6666,
    "msg": "成功",
    "time": "20190723112526",
    "data": {
        "t": "0000" （0000 = 正常，0100 = 欠费、停机，0200 = 黑名单，0300 = 号码不存在）
    },
    "srs": null
}
 * @description: get类型请求, 查询手机号状态
 * eg: storeBindingPhone=17665130350
*/
const getPhoneStatus = (params, data) => {
    wx.request({
        url: `${PROJECTNAME}/restaurant-store/shop/getPhoneStatus`, //仅为示例，并非真实的接口地址
        data,
        success (res) {
            params.success(res.data);
        }
    })
};

/**
 * @author Dom
 * @param params, type: object
 * state: 请求配置, 具体说明参照 /utils/requestWrapper.js
 * @param data , type: object
 * state: { formIds: [], //formId的数组 },
 * @return: {
    "code": 6666,
    "msg": "成功",
    "time": "20190723112526",
    "data": null,
    "srs": null
}
 * @description: post类型请求, 收集formId, 用于推送消息模版
 */
const postFormIdCollect = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-order/order/formIdCollect'
    }, data);
};

/**
 * @author Dom
 * @param params, type: object
 * state: 请求配置, 具体说明参照 /utils/requestWrapper.js
 * @param data, type:
 * state: 无需传递参数
 * @description: 微信支付, 用于测试发起支付功能, 仅用于测试支付功能, 实际并不需要使用。
 */
const postUnifiedOrder = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-order/pay/unifiedOrder'
    }, data)
};

/**
 * @author Dom
 * @param params, type: object
 * state: 请求配置, 具体说明参照 /utils/requestWrapper.js
 * @param data, type: object
 * state: { param: 渠道号之外的其他参数, resource: 渠道号 }
 * param, JSON字符串, 把前后的大括号去掉, eg: JSON.stringify({ storeId: this.data.storeId }).slice(1, -1)
 * resource, 渠道号字符串, 暂时由项目经理进行定义。
 * @description: 统计接口
*/
const postLog = (params, data) => {
    if(isDev) return;
    requestWrapper({
        ...params,
        url: 'https://smarthome.17wo.cn/statistics/statis/log'
    }, data)
};

/**
 * @author Dom
 * @param params, type: object
 * state: 请求配置, 具体说明参照 /utils/requestWrapper.js
 * @param data, type:
 * state: 无需传递参数
 * @description: 获取自定义tabbar的数据
*/
const postTabs = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-user/index/getTabs'
    }, data)
};

/**
 * @author Dom
 * @param params, type: object
 * state: 请求配置, 具体说明参照 /utils/requestWrapper.js
 * @param data, type: object
 * state: { phone, icode }
 * phone, 需要绑定的手机号
 * icode, 短信验证码, 由postSendICode获取
 * @description: 用于绑定手机号
 */
const postBinding = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-user/user/binding'
    }, data)
};

/**
 * @author Dom
 * @param params, type: object
 * state: 请求配置, 具体说明参照 /utils/requestWrapper.js
 * @param data, type: object
 * state: { phone }
 * phone, 需要绑定的手机号
 * @description: 用于获取绑定手机号过程中, 获取短信验证码
 */
const postSendICode = (params, data) => {
    requestWrapper({
        ...params,
        url: '/restaurant-user/user/sendICode'
    }, data)
};

module.exports = {
    postWechatPhoneNumber,
    getFindBylevId,
    postAddShop,
    postAddShopRegister,
    postEditShop,
    postShopList,
    postShopData,
    postIndexList,
    postStores,
    postCancelSeason,
    postPartCancel,
    postMine,
    postSpuList,
    postSkuInfo,
    postDishSpuName,
    postPlaceOrder,
    postPayQuery,
    postUser,
    postUnbind,
    postOrderDetails,
    postCoupon,
    postEntryPhone,
    postAddCategory,
    postDelCategory,
    postDishDelete,
    getStoreManagerInfo,
    postUpdateStore,
    postChangeStoreStatus,
    postStoreConfigData,
    postEditStoreConfigData,
    postUpdateAptitude,
    postUpdateManager,
    getPhoneStatus,
    postFormIdCollect,
    postUnifiedOrder,
    postInsertSaveDish,
    postUpdateSaveDish,
    postCategoryList,
    postDishMsg,
    postPrinterinfo,
    postUpdateprinter,
    postCount,
    postPrinterlist,
    postBackPrinterlist,
    postRemoveprinter,
    postAddprinter,
    postFindStoreByUserId,
    postCheckQrBindJurisdiction,
    postBindStoreQR,
    postUpdateStoreQrCode,
    postUpdateOnsale,
    postLog,
    postTabs,
    postBinding,
    postSendICode
};